<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     default_default
 */

/**
 * @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle
 * @var Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle $this
 */
?>
<script type="text/javascript">
if(typeof Bundle=='undefined') {
    Bundle = {};
}
</script>

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('bundle')->__('Shipment') ?></h4>
    </div>
    <fieldset>
        <table cellspacing="0" class="form-list">
        <tr>
            <td class="label"><label for="shipment_type"><?php echo Mage::helper('bundle')->__('Ship Bundle Items') ?></label></td>
            <td class="value"><select <?php if ($this->isReadonly()): ?>disabled="disabled" <?php endif ?>id="shipment_type" name="<?php echo $this->getFieldSuffix() ?>[shipment_type]" class="select">
                <option value="1"><?php echo Mage::helper('bundle')->__('Separately') ?></option>
                <option value="0"<?php if ($this->getProduct()->getShipmentType() == 0): ?> selected="selected"<?php endif ?>><?php echo Mage::helper('bundle')->__('Together') ?></option>
            </select>
            </td>
        </tr>
        </table>
    </fieldset>
</div>

<div class="entry-edit custom-options bundle" id="product_bundle_container">
    <div class="entry-edit-head">
        <h4><?php echo $this->__('Bundle Items') ?></h4>
        <div class="right"><?php echo $this->getAddButtonHtml() ?></div>
    </div>

    <div id="product_options_container" class="box">
        <div id="product_bundle_container_top"></div>
        <?php echo $this->getOptionsBoxHtml() ?>
    </div>
</div>

<script type="text/javascript">
// re-bind form elements onchange
varienWindowOnload(true);
<?php if ($this->isReadonly()):?>
$('product_bundle_container').select('input', 'select', 'textarea', 'button').each(function(input){
    input.disabled = true;
    if (input.tagName.toLowerCase() == 'button') {
        input.addClassName('disabled');
    }
});
<?php endif ?>
Validation.add('validate-greater-zero-based-on-option', '<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Please enter a number greater 0 in this field.')) ?>', function(v, el) {
    var optionType = $(el).up('div.grid').previous('table.option-header').select('select.select-product-option-type')[0],
        v = Number(v) || 0;

    if (optionType && (optionType.value == 'checkbox' || optionType.value == 'multi') && v <= 0) {
        return false;
    }
    return true;
});
</script>

<div><input type="hidden" name="affect_bundle_product_selections" value="1" /></div>
